<?php include("./header.php");?>
<?php 
function filter_file_name($name,$is_dir=false){
	if(ereg('#',$name))
	{
		$name = str_replace('#','_',$name);
	}
	
	$name = str_replace(array('\\','/',':','*','?','"',"'",'<','>','|'),'#',$name);
	
	if(strpos($tmp_new,'#') > -1)
	{
		do_alert(label("common.name_input_error"));
		return;
	}
	
	if(!$is_dir)
	{
		$tmp_new = str_replace(' ','#',trim($tmp_new));
	
		if(strpos($tmp_new,'#') > -1)
		{
			do_alert(label("common.name_space_error"));
			return;
		}
	}
	
	return $name;
}

$system_flag = get("system_flag");
$root = to_os_encoding(deep_get("EXPLOER_ROOT",false,get_real_folder("./")));
$path = $currentPath;
//echo $path . get("fileName") . "<br/>" ;
  
if($system_flag == "editFile"){
	$name = to_os_encoding(get('name'));
	$is_dir = is_dir($path.$name);
	$new_name = to_os_encoding(trim(get('newName')));
	
	$new_name = filter_file_name($new_name,$is_dir);
	$type = get_file_type($new_name);
	$result = 1;
	if(!$is_dir){
		if(!$type){
			$result = 2;
		}else if(in_array($type, $block_types)){
			$result = 3;
		}
	}
	
	if(file_exists($path.$new_name) && $name != $new_name){
		$result = 4;
	}
	
	if($name != $new_name && !rename($path.$name, $path . $new_name) ){
		$result = 5;
	}
}else if($system_flag == "deleteFile"){
	$name = to_os_encoding(get('name'));
	$temp = $path . $name ;
	  
	if(is_dir($temp)){
		$result = delete_dir($temp) ;
	}else {
		$result = unlink($temp) ;
	} 
}else if($system_flag == "createNewFolder"){ 
	$folderName = get("folderName") .date("ymdHis");
	$dir_name = $currentPath .$folderName ;   
	$result = mkdir($dir_name); 
}else if($system_flag == "download_file"){
	
}
ob_clean();
echo json_encode($result);
die();
?>
<?php include("./footer.php");?>